const path = require('path')
const {VueLoaderPlugin} = require('vue-loader')

const glob = require('glob')
const list = {}
// 动态的读取components文件夹下的组件
const readFolder = async (path, list) => {
    const files = glob.sync(`${path}/**/index.js`)
    for (const file of files) {
        const name = file.split(/[./]/)[2]
        list[name] = './' + file
    }
}
readFolder('components/lib', list)
console.log(list)
module.exports = {
    entry: list,
    mode: 'production',
    output: {
        // 这里不能使用相对路径 dist
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].umd.js', // 不同组件最终名次like btn.umd.js
        library: 'umi',
        libraryTarget: 'umd'
    },
    plugins: [
        new VueLoaderPlugin()
    ],
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.css$/,
                use: [
                    'vue-style-loader',
                    'css-loader'
                ]
            }
        ]
    }
}
